package com.sky.controller.user;

import com.sky.context.BaseContext;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author
 * @Date 2024/5/12 14:53
 * @Description:
 */


@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api(tags = "购物车")
public class ShoppingCartController {


    @Autowired
    private ShoppingCartService shoppingCartService;
    @PostMapping("/add")

    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车：{}",shoppingCartDTO);
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        Long wxId = BaseContext.getCurrentId();
        log.info("查询用户：{}购物车",wxId);
        List<ShoppingCart> list = shoppingCartService.cartList(wxId);
        return Result.success(list);
    }
    @DeleteMapping("/clean")
    public Result delete(){
        Long wxId = BaseContext.getCurrentId();
        log.info("用户：{}清空购物车",wxId);
     shoppingCartService.cleanShoppingCart(wxId);
     return Result.success();
    }
}
